#ifndef MYSQL_H
#define MYSQL_H

#include <QWidget>
#include <QSqlDatabase>
#include <QtCore/QMutex>
#include "Beans/databeans.h"

class MySql
{
public:
    MySql(QString& Dir);
    ~MySql();

private:
    bool CreateConnection();      //创建数据库连接//
    bool isDirExist();            //路径是否存在//

    QString connectionName;       //连接名称//
    QString dbDir;                //.db文件路径//
    QSqlDatabase db;
    QMutex mutex;                 //多线程资源访问控制//
public:
    void closeDb();               //关闭数据库//

    bool MyInsert(DataBeans& InputImgInfo);                   //插入//
    bool MySelect(QString UserID,DataBeans& userInfo);      //查找//
    bool Query(QString userID);
    bool MyDelete(QString UserID);                               //删除//
    bool MyUpdate(DataBeans& userInfo);                   //更新//

    bool MyUpdateLoginState_All();
    QList<DataBeans> QueryAll();
    bool MyDataDelete(QString Measuretime);
    QList<DataBeans> DataQueryBy(QString ID,QString MeasureTime1,QString MeasureTime2);
    DataBeans DataQueryByMeasureTime(QString MeasureTime);

private:
    void  requestAccessToken(void);                           //加锁//
    void  releaseAccessToken(void);                           //解锁//

};

#endif // MYSQL_H
